<include file="Public:header" />
<div class="container">
	<div class="page-header">
		<h4><a name="tab">{:L('THE_CONTRACT_DETAILS')}</a></h4>
	</div>
	<include file="Public:alert"/>
	<div class="row">
		<div class="tabbable span12">
			<ul class="nav nav-tabs">
				<li><a href="#tab1">{:L('BASIC_INFO')}</a></li>
				<li><a href="#tab2">{:L('PRODUCT')}({$info['product_count']})</a></li>
				<li><a href="#tab3">{:L('FINANCE')}({$info['finance_count']})</a></li>
				<li><a href="#tab4">{:L('FILE')}({$info['file_count']})</a></li>
			</ul>
			<div class="tab-content">
				
					<table class="table table-hover">
						<thead>
							<tr> 
								<td <if condition="C('ismobile') eq 1">colspan="2"<else />colspan="4"</if>>
								<p style="font-size: 14px;">
									<if condition="$info['is_deleted'] == 0">
									<a href="javascript:void(0);" class="add_product">{:L('ADD_PRODUCT')}</a> | 								
									<a href="javascript:void(0);" class="add_file">{:L('ADD_ACCESSORY')}</a> | 								
									<a href="{:U('contract/edit', 'id='.$info['contract_id'])}">{:L('EDITING')}</a> | 
									<a href="{:U('contract/delete', 'contract_id='.$info['contract_id'])}" class="del_confirm">{:L('DELETE')}</a> | 
									</if>
									<a href="javascript:void(0)" onclick="javascript:history.go(-1)">{:L('RETURN')}</a>
								</p>
								</td>
							</tr>
						</thead>
						<tbody>
							<tr><th <if condition="C('ismobile') eq 1">colspan="2"<else />colspan="4"</if>>{:L('BASIC_INFO')}</th></tr>
							<tr>
								<td class="tdleft">{:L('CONTRACT_NO')}</td>
								<td>{$info.number}</td>
								<if condition="C('ismobile') eq 1"></tr><tr></if>
								<td class="tdleft">{:L('BUSINESS')}</td>
								<td><a href="{:U('business/view','id='.$info['business_id'])}">{$info.business_name}</a></td>
							</tr>
							<tr>
								<td class="tdleft">{:L('CUSTOMER')}</td>
								<td><a href="{:U('customer/view','id='.$info['customer_id'])}">{$info.customer_name}</a></td>
								<if condition="C('ismobile') eq 1"></tr><tr></if>
								<td class="tdleft">{:L('CREATOR_ROLE')}</td>
								<td><a class="role_info" href="javascript:void(0)" rel="{$info['creator_role_id']}">{$info.creator_name}</a></td>
							</tr>
							<tr>
								<td class="tdleft">{:L('CONTACTS')}</td>
								<td>{$info.contacts_name}</td>
								<if condition="C('ismobile') eq 1"></tr><tr></if>
								<td class="tdleft">{:L('OWNER_ROLE')}</td>
								<td><a class="role_info" rel="{$info['owner_role_id']}" href="javascript:void(0)">{$info['owner_name']}</a></a></td>
							</tr>
							<tr>
								<td class="tdleft">{:L('THE_TIME_WHICH_THE_CONTRACT_COMES_INTO_FORCE')}</td>
								<td>
									<if condition="$info['start_date']">{$info['start_date']|date="Y-m-d",###}</if>
								</td>
								<if condition="C('ismobile') eq 1"></tr><tr></if>
								<td class="tdleft">{:L('CONTRACT_TIME')}</td>
								<td>
									<if condition="$info['end_date']">{$info['end_date']|date="Y-m-d",###}</if>
								</td>
							</tr>
							<tr>
								<td class="tdleft">{:L('SIGNING_TIME')}</td>
								<td>{$info.due_time|date="Y-m-d",###}</td>
								<if condition="C('ismobile') eq 1"></tr><tr></if>
								<td class="tdleft">{:L('UPDATE_TIME')}</td>
								<td>{$info.update_time|date="Y-m-d",###}</td>
							</tr>
							<tr>
								<td class="tdleft">{:L('QUOTATION')}</td>
								<td>{$info.price}</td>
								<if condition="C('ismobile') eq 1"></tr><tr></if>
								<td class="tdleft">{:L('STATUS')}</td>
								<td>{$info.status}</td>
							</tr>
							<tr>
								<td class="tdleft">{:L('THE_TERMS_OF_THE_CONTRACT')}</td>
								<td <if condition="C('ismobile') neq 1">colspan="3"</if>><if condition="$info.content neq null"><pre>{$info.content}</pre></if></td>
							</tr><tr>
								<td class="tdleft">{:L('DESCRIBE')}</td>
								<td <if condition="C('ismobile') neq 1">colspan="3"</if>><if condition="$info.description neq null"><pre>{$info.description}</pre></if></td>
							</tr>
						</tbody>
					</table>
                    <a name="tab2"></a><div style="height:40px;"></div>
                    <table class="table table-hover">
                        <tr>
                            <th>{:L('RELATED_PRODUCTS')}</th>
                        </tr>
                    </table>
                    <table class="table">
						<if condition="$info.product eq null">
							<tr>
								<td>{:L('THERE_IS_NO_DATA')} </td>
							</tr>
						<else /> 
							<thead>
								<tr>
									<td>&nbsp;</td>
									<td>{:L('PRODUCT_NAME')}</td>
									<td>{:L('PRODUCT_CATEGORY')}</td>
									<if condition="C('ismobile') neq 1">
									<td>{:L('QUOTATION_YUAN')})</td>
									</if>
									<td>{:L('TRADING_YUAN')}</td>
									<if condition="C('ismobile') neq 1">
									<td>{:L('THE_COST_PRICE_YUAN')}</td>
									<td width="30%">{:L('REMARK')}</td>
									</if>
								</tr>
							</thead>
							<tbody>
								<volist name="info.product" id="vo">
									<tr>
										<td class="tdleft"><a href="{:U('product/mdelete', 'r=rContractProduct&id='.$vo['id'])}" class="del_confirm">{:L('DELETE')}</a>&nbsp;<a class="edit_product" href="javascript:void(0)" rel="{$vo.id}">{:L('EDITING')}</a></a></td>
										<td>
											<a href="{:U('product/view', 'id='.$vo['product_id'])}">{$vo.info.name}</a>
										</td>
										<td>
											{$vo.category_name}
										</td>
										<if condition="C('ismobile') neq 1">
										<td>
											<if condition="$vo['estimate_price'] gt 0">{$vo.estimate_price}</if>
										</td>
										</if>
										<td>
											<if condition="$vo['sales_price'] gt 0">{$vo.sales_price}</if>
										</td>
										<if condition="C('ismobile') neq 1">
										<td>
											<if condition="$vo['info']['cost_price'] gt 0">{$vo.info.cost_price}</if>
										</td>
										<td>
											{$vo.description}
										</td>
										</if>
									</tr>
								</volist>
							</tbody>
						</if>
						<if condition="$info['is_deleted'] == 0">
						<tr>
							<td colspan="7">
								<a href="javascript:void(0);" class="add_product">{:L('ADD')}</a>
							</td>
						</tr>
						</if>
					</table>
                    <a name="tab3"></a><div style="height:40px;"></div>
					<h5>{:L('THE_ACCOUNTS_RECEIVABLE')}</h5>
					<table class="table">
						<if condition="$info.receivables eq null">
							<tr>
								<td>{:L('THERE_IS_NO_DATA')}</td>
							</tr>
						<else />
							<thead>
								<tr>
									<td width="10%">&nbsp;</td>
									<td>{:L('THE_ACCOUNTS_RECEIVABLE_NAME')}</td>
									<td>{:L('STATUS')}</td>
									<td>{:L('MONEY')}</td>
									<if condition="C('ismobile') neq 1">
									<td>{:L('OWNER_ROLE')}</td>
									</if>
								</tr>
							</thead>
							<tbody>
								<volist name="info.receivables" id="vo">
									<tr>
										<td class="tdleft">
											<a href="{:U('finance/delete', 't=receivables&id='.$vo['receivables_id'].'&refer=receivables')}" class="del_confirm">{:L('DELETE')}</a>
											<a  href="{:U('finance/edit', 't=receivables&id='.$vo['receivables_id'])}" target='blank' >{:L('EDITING')}</a></a>
											</td>
										<td>
											<a href="{:U('finance/view', 't=receivables&id='.$vo['receivables_id'])}" target='blank'>{$vo.name}</a>
										</td>
										<td>
											<if condition="$vo['status'] eq 2">{:L('HAS_BEEN_RECEIVING')}<elseif condition="$vo['status'] eq 1" />{:L('PART_OF_THE_RECEIVED')}<else />{:L('DID_NOT_RECEIVE_PAYMENT')}</if>
										</td>
										<td>
											{$vo['price']}
										</td>
										<if condition="C('ismobile') neq 1">
										<td>
											<a class="role_info" href="javascript:void(0)" rel="{$vo['owner_role_id']}">{$vo['owner']['user_name']}</a>
										</td>
										</if>
									</tr>
								</volist>
							</tbody>
						</if>
						<if condition="$info['is_deleted'] == 0">
						<tr>
							<td colspan="6">
								<a href="javascript:void(0);" class="add_receivables">{:L('ADD')}</a>
							</td>
						</tr>
						</if>
					</table>
					<h5>{:L('THE_ACCOUNTS_PAYABLE')}</h5>
					<table class="table">
						<if condition="$info.payables eq null">
							<tr>
								<th colspan="6">{:L('THERE_IS_NO_DATA')}</th>
							</tr>
						<else />
							<thead>
								<tr>
									<th width="10%">&nbsp;</th>
									<th>{:L('THE_ACCOUNTS_PAYABLE_NAME')}</th>
									<th>{:L('STATUS')}</th>
									<th>{:L('MONEY')}</th>
									<if condition="C('ismobile') neq 1">
									<th>{:L('OWNER_ROLE')}</th>
									</if>
								</tr>
							</thead>
							<tbody>
								<volist name="info.payables" id="vo">
									<tr>
										<td class="tdleft">
											<a href="{:U('finance/delete', 't=payables&id='.$vo['payables_id'].'&refer=payables')}" class="del_confirm">{:L('DELETE')}</a>
											<a  href="{:U('finance/edit', 't=payables&id='.$vo['payables_id'])}" target='blank' >{:L('EDITING')}</a></a>
											</td>
										<td>
											<a href="{:U('finance/view', 't=payables&id='.$vo['payables_id'])}" target='blank'>{$vo.name}</a>
										</td>
										<td>
											<if condition="$vo['status'] eq 2">{:L('PAYMENT_HAS_BEEN')}<elseif condition="$vo['status'] eq 1" />{:L('PART_OF_THE_PREPAID')}<else />{:L('NOT_PAYING')}</if>
										</td>
										<td>
											{$vo['price']}
										</td>
										<if condition="C('ismobile') neq 1">
										<td>
											<a class="role_info" href="javascript:void(0)" rel="{$vo['owner_role_id']}">{$vo['owner']['user_name']}</a>
										</td>
										</if>
									</tr>
								</volist>
							</tbody>
						</if>
						<if condition="$info['is_deleted'] == 0">
						<tr>
							<td colspan="6">
								<a href="javascript:void(0);" class="add_payables">{:L('ADD')}</a>
							</td>
						</tr>
						</if>
					</table>
                    <a name="tab4"></a><div style="height:40px;"></div>
                    <table class="table table-hover">
                        <tr>
                            <th>{:L('RELATED_FILE')}</th>
                        </tr>
                    </table>
					<table class="table">
						<if condition="$info.file eq null">
							<tr>
								<td>{:L('THERE_IS_NO_DATA')} </td>
							</tr>
						<else /> 
							<tr>
								<td>&nbsp;</td>
								<td>{:L('FILE_NAME')}</td>
								<td>{:L('SIZE')}</td>
								<td>{:L('ADDED_BY')}</td>
								<td>{:L('ADD_TIME')}</td>
							</tr>
							<volist name="info.file" id="vo">
								<tr>
									<td class="tdleft"><a href="{:U('file/delete','r=rContractFile&id='.$vo['file_id'])}" class="del_confirm">{:L('DELETE')}</a></td>
									<td>
										<a target="_blank" href="{$vo.file_path}">{$vo.name}</a>
									</td>
									<td>
										{$vo.size}{:L('BYTE')}
									</td>
									<td>
										<notempty name="vo.owner.user_name">{$vo.owner.user_name} [{$vo.owner.department_name}-{$vo.owner.role_name}]</notempty>
									</td>
									<td>
										<notempty name="vo.create_date">{$vo.create_date|date="Y-m-d g:i:s a",###}</notempty>
									</td>
								</tr>
							</volist>
						</if>
						<if condition="$info['is_deleted'] == 0">
						<tr>
							<td colspan="5">
								<a href="javascript:void(0);" class="add_file">{:L('ADD')}</a>
							</td>
						</tr>
						</if>
					</table>
				</div>
			</div>
		</div>
	</div>
</div>
<div class="hide" id="dialog-product" title="{:L('ADD_PRODUCT')}">loading...</div>
<div class="hide" id="dialog-edit" title="{:L('AMENDING_THE_CONTRACT_PRODUCT_INFORMATION')}">loading...</div>
<div class="hide" id="dialog-role-info" title="{:L('DIALOG_USER_INFO')}">loading...</div>
<div class="hide" id="dialog-receivables" title="{:L('ADD_THE_ACCOUNTS_RECEIVABLE')}">loading...</div>
<div class="hide" id="dialog-payables" title="{:L('ADD_THE_ACCOUNTS_RECEIVABLE')}">loading...</div>
<div class="hide" id="dialog-file" title="{:L('ADD_ACCESSORY')}">loading...</div>
<script>

<if condition="C('ismobile') eq 1">width=$('.container').width() * 0.9;<else />width=800;</if>
$("#dialog-product").dialog({
    autoOpen: false,
    modal: true,
	width: width,
	maxHeight:400,
	position: ["center",100]
});
$("#dialog-edit").dialog({
    autoOpen: false,
    modal: true,
	width: width,
	maxHeight:400,
	position: ["center",100]
});
$("#dialog-role-info").dialog({
    autoOpen: false,
    modal: true,
	width: width,
	maxHeight:400,
	position: ["center",100]
});
$("#dialog-receivables").dialog({
    autoOpen: false,
    modal: true,
	width: width,
	maxHeight:400,
	position: ["center",100]
});
$("#dialog-payables").dialog({
    autoOpen: false,
    modal: true,
	width: width,
	maxHeight:400,
	position: ["center",100]
});
$("#dialog-file").dialog({
    autoOpen: false,
    modal: true,
	width: width,
	maxHeight: 400,
	position: ["center",100]
});
$(function(){
	$(".edit_product").click(function(){
		id = $(this).attr('rel');
		$('#dialog-edit').dialog('open');
		$('#dialog-edit').load('{:U("product/editdialog","r=RContractProduct&id")}'+id);
	});
	$(".add_product").click(function(){
		$('#dialog-product').dialog('open');
		$('#dialog-product').load('{:U("product/adddialog","r=RContractProduct&module=contract&id=".$info["contract_id"])}');
	});
	$(".role_info").click(function(){
		$role_id = $(this).attr('rel');
		$('#dialog-role-info').dialog('open');
		$('#dialog-role-info').load('{:U("user/dialoginfo","id=")}'+$role_id);
	});
	$(".add_receivables").click(function(){
		$('#dialog-receivables').dialog('open');
		$('#dialog-receivables').load('{:U("finance/adddialog", "t=receivables&contract_id=".$info['contract_id'])}');
	});
	$(".add_payables").click(function(){
		$('#dialog-payables').dialog('open');
		$('#dialog-payables').load('{:U("finance/adddialog", "t=payables&contract_id=".$info['contract_id'])}');
	});
	$(".add_file").click(function(){
		$('#dialog-file').dialog('open');
		$('#dialog-file').load('{:U("file/add","r=RContractFile&module=contract&id=".$info["contract_id"])}');
	});
	$('.del_confirm').click(function(){
		if(confirm('{:L("CONFIRM_DELETE")}')){
			return true;
		}else{
			return false;
		}
	});
});
</script>
<include file="Public:footer" />	